<!doctype html>
<html>

	<head>
		<title>注册</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="assets/css/amazeui.min.css">
		<link rel="stylesheet" href="assets/css/style.css">
		<script src="assets/js/jquery.min.js"></script>
	</head>
	<body class="body">
		<div class="containter">
			<header data-am-widget="header" class="am-header am-header-default">
				<div class="am-header-left am-header-nav">
					<a href="javascript:;" onClick="javascript :history.back(-1);">
						<img src="assets/images/left.png">
					</a>
				</div>
				<h1 class="am-header-title" style="margin:0 14%">注册</h1>
			</header>
			<div style="height: 4rem; width: 100%;"></div>
			<div class="change">
				<form action="">
					<ul>
						<li class="zh">
							<input id="phonenumber" type="text" placeholder="请输入您的手机号" maxlength="11">
						</li>
						<li class="yz">
							<input id="erification_code" type="text" placeholder="请输入短信验证码">
							<button type="button" class="getcode">获取短信验证码</button>
						</li>
						<li>
							<input id="pass_word" type="password" placeholder="请输入您的密码">
							<a href="javascript:;" class="close"></a>
						</li>
						<li>
							<input id="contain_word" type="password" placeholder="请再次输入您的密码">
							<a href="javascript:;" class="close"></a>
						</li>
					</ul>
					<button type="button" class="regandlog">注册并登陆</button>
				</form>
			</div>
		</div>
		<div id="toast" style="top:-11.5rem"></div>
		<script type="text/javascript">
			$(function() {
				$(".close").click(function() {
					$(this).toggleClass("close");
					$(this).toggleClass("key");
					if($(this).is('.key')) {
						$(this).parents("li").find("input").attr("type", "text");
					} else {
						$(this).parents("li").find("input").attr("type", "password");
					}
				});
			});
		</script>

	</body>
	<script src="assets/js/allUse.js"></script>
	<script src="assets/js/jquery.md5.js"></script>
	<!--5.1 手机注册-->
	<script type="text/javascript">
		var regn = /^[0-9]*$/
		$("#phonenumber").on("keyup",function(){
			if(!regn.test($(this).val())){
				$(this).val($(this).val().substring(0,$(this).val().length-1))
			}
		})
		var flg=true;
		$('.regandlog').click(function() {
			var phone_num = $.trim($("#phonenumber").val());
			var verification_code = $.trim($("#erification_code").val());
			var pass_word =$.md5($.md5($.trim($("#pass_word").val())));
			var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
			var rxpassword = /^[a-zA-Z0-9]{6,18}$/;
			if(!phone_num){
				showToast("请输入手机号")
				return;
			}else if(!rxPhone.test(phone_num)){
				showToast("手机号码有误");
				return;
			}else if(!verification_code){
				showToast("请输入验证码");
				return;
			}else if(!rxpassword.test($.trim($("#pass_word").val()))){
				showToast("密码长度应为6-18位并且为字母数字组合");
				return;
			}else if($.trim($("#pass_word").val())!==$.trim($("#contain_word").val())){
				showToast("两次密码不一致");
				return;
			}else if(!flg){
				return;
			}
			flg=false
			$(function() {
				$.ajax({
					type: "post",
					url: url_enter+"/api/register",
					header: {
						
						"Os":ios_Andriod,
						"Device-Id":"",
						"Screen":wh,
						"Content-Type": "application/x-www-form-urlencoded"
					},
					data: {
						
						"phone_num": phone_num, //注册手机号，字符串类型（String）
						"verification_code": verification_code, //短信验证码，字符串类型（String）
						"password":pass_word //用户密码，未加密，字符串类型（String）
					},
					success: function(data, status, xhr) {
						flg=true
						console.log(data)
						if(data.result==1){
							alert(data.message)
							sessionStorage.user_id=data.data.user_id;
							sessionStorage.token=data.data.token;
							$.ajax({
								type:"post",
								url:url_enter+"/api/get_my_travel_mavin",
								async:false,
								headers: {
									"token":data.data.token,
									"Os": ios_Andriod,
									"Device-Id": "",
									"Screen":wh,
									"Content-Type": "application/x-www-form-urlencoded"
								},
								data:{},
								success:function(data){
									console.log(data);
									if(data.result===1){//成功啦
										if(data.data!==null){//用户存在旅游专家 则调用存在旅游专家的方法 live1;
											var obj4='{"dep_id":"'+data.data.dep_id+'","head_img":"'+data.data.head_img+'","names":"'+data.data.names+'","dep_name":"'+data.data.dep_name+'","phone_num":"'+data.data.phone_num+'"}'
											console.log(obj4);
											sessionStorage.setItem("my_volg",obj4);
											if(document.referrer&&sessionStorage.getItem('registerBack')){
												window.location.href=sessionStorage.getItem('registerBack');
											}else{
												window.location.href="index.html";	
											}
										}else{
											var obj4="un";//若判断"my_volg"的值为"un"则不存在旅游专家 调用不存在旅游专家的方法 live2
											sessionStorage.setItem("my_volg",obj4);
											if(document.referrer&&sessionStorage.getItem('registerBack')){
												window.location.href=sessionStorage.getItem('registerBack');
											}else{
												window.location.href="index.html";	
											}
										}
									}
									
									
								}
							});
							window.location.href="index.html";
						}else{
							alert(data.result)
						}
					},
					error: function(xhr, status, thrown) {
						console.log(xhr);
					}
				});
			});
		});
	</script>

	<!--5.2获取验证码-->
	<script type="text/javascript">
		var flag1=true
		$('.getcode').click(function() {
				if(flag1){
					getcode();
				}
		});
		function calc(){//倒计时
			var initTime=60;
			var timer=setInterval(function(){
				initTime--
				if(initTime===0){
					showinner(false,initTime)
					flag1=true
					clearInterval(timer)					
				}else{
					showinner(true,initTime)
				}
				
			},1000)
		}
		function showinner(flag,time){
			if(flag){
				$(".getcode").html(time)
			}else{
				$(".getcode").html("获取短信验证码")
			}
		}
		function getcode(){
			var phone_num = $(" #phonenumber ").val();
			//			console.log(phone_num);
			var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
			if(!phone_num){
				showToast("请输入手机号")
				return;
			}else if(!rxPhone.test(phone_num)){
				showToast("手机号码有误");
				return;
			}
			$(function() {
				$.ajax({
					type: "get",
					url: url_enter+"/api/get_sms_verify_code",
					header:headers,
					data: {
						"phone_num": phone_num, //注册手机号，字符串类型（String）
						'types': 'register' // 验证码使用类型 注册|重置密码|…
					},
					success: function(data, status, xhr) {
						console.log(data);
						if(data.result===1){
							flag1=false
							calc()	
						}else{
							alert(data.message)
						}
					},
					error: function(xhr, status, thrown) {
						console.log(xhr);
					}
				});
			});
		}
		//		$(".getcode").on("click", function() {
		//			console.log(123);
		//		});
	</script>

</html>